package com.backend.demo1.controller;

import com.backend.demo1.config.ApiResponse;
import com.backend.demo1.models.User;
import com.backend.demo1.services.AuthService;



import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Autowired
    private AuthService authService;
    
    

    @PostMapping("/register")
    public ResponseEntity<ApiResponse<String>> register(@RequestBody User user) {
        // 调用注册逻辑
        String token = authService.register(user);
        return ResponseEntity.ok(new ApiResponse<>(200, "注册成功", token));
    }

    @PostMapping("/login")
    public ResponseEntity<ApiResponse<Map<String, Object>>> login(@RequestBody User input) {
        
        // 调用登录逻辑
        Map<String, Object> response = authService.login(input);
        return ResponseEntity.ok(new ApiResponse<>(200, "登录成功", response));
    }

}